package com.linkoog.devtools.type.javadoc;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class JavaDoc {

    private String context;
    private String description;
    private List<JavaComment> tagComments;


    public List<JavaComment> getJavaCommentByNames(@NotNull String... names) {
        if (tagComments == null || tagComments.isEmpty() || names == null || names.length == 0) {
            return null;
        }

        return tagComments.stream().filter(javaComment -> Arrays.stream(names).anyMatch(name -> name.equals(javaComment.getName()))).collect(Collectors.toList());
    }

    public JavaComment getJavaComment(@NotNull String name,@NotNull String tagName) {
        if (tagComments == null || tagComments.isEmpty() || StringUtils.isBlank(name)) {
            return null;
        }

        return tagComments.stream().filter(javaComment -> name.equals(javaComment.getName()) && tagName.equals(javaComment.getKey())).findFirst().orElse(null);
    }

    @Override
    public String toString() {
        return "Comment{" +
                "context='" + context + '\'' +
                ", tagComments=" + tagComments +
                '}';
    }


}
